var myvue = new Vue({
	el: "body",
	data: {
		time: "",
		userid: "",
		info: "",
		work: "",
		nowtime: "",
		myid: "",
		showimg:"",
		imgindex:0
	},
	methods: {
		click: function(e) {
			this.showimg=e;
			this.imgindex=0;
			console.log(e);
			$(".big").css("display", "none");
			$(".allbig").css("display", "-webkit-box").css("height", $(window).height());
		},
		close: function() {
			$("#my-alert").modal('close');
			setfun();
		},
		nextdiv:function(e){
			if(e==this.showimg.main.length-1){
				this.imgindex=0;
			}else{
				this.imgindex++;
			}
		}
	},
	created: function() {
		init();
	},
	beboremount: function() {

	}
})

//初始化
function init() {
	var APP_ID = 'Wx3JTgmqBaARoWCaGI96AM9h-gzGzoHsz';
	var APP_KEY = 'TrVpB16Og6Yac9u3BoiUy4hT';
	AV.init({
		appId: APP_ID,
		appKey: APP_KEY
	});
	//不登录无法浏览此页面
	var curr = AV.User.current();
	if(curr) {
		console.log("欢迎" + curr.attributes.username + "的光临");
		this.myid = curr.id;
	} else {
		console.log("未登录");
	};
	//截取url
	var reg = new RegExp("(^|&)" + "id" + "=([^&]*)(&|$)", "i");
	var r = window.location.search.substr(1).match(reg);
	if(r != null) {
		this.userid = unescape(r[2]);
	} else {
		console.log(null);
	};
	//查询
	var query = new AV.Query('otherUser');
	query.get(this.userid).then(function(e) {
		// results 即为查询结果，它是一个 AV.Object 数组
		myvue.info = e;
		myvue.work = e.attributes.work;
		myvue.time = e.attributes.trip;
		console.log(myvue.info);
		//		myvue.$nextTick(function() {
		timePickInit(myvue.time);
		//		})
	}, function(error) {
		console.log("查询失败");
	});
}
//支付后点击确定更新云端
function setfun() {
	// 声明类型
	var TodoFolder = AV.Object.extend('order');
	// 新建对象
	var todoFolder = new TodoFolder();
	// 设置名称
	todoFolder.set('userid', this.myid);
	todoFolder.set('otherid', this.userid);
	todoFolder.set('oldtime', formatDate(new Date));
	todoFolder.set('phone', myvue.info.attributes.phone);
	todoFolder.set('other', myvue.info.attributes.class);
	todoFolder.set('time', myvue.nowtime);
	todoFolder.set('othername', myvue.info.attributes.name);
	todoFolder.set('state', "1");
	todoFolder.set('info', true);
	todoFolder.set('headimg', myvue.info.attributes.headimg);

	// 设置优先级
	//	todoFolder.set('priority', 1);
	todoFolder.save().then(function(todo) {
		console.log("ok");
		//		console.log('objectId is ' + todo.id);
	}, function(error) {
		console.error(error);
	});
	//更新日程
	// 第一个参数是 className，第二个参数是 objectId
	var todo = AV.Object.createWithoutData('otherUser', this.userid);
	// 修改属性
	var newarr = myvue.info.attributes.trip;
	newarr.unshift(myvue.nowtime);
	myvue.time = newarr;
	//重新运行日历
	$('.maintime').datepicker.onRender;
	// 保存到云端
	todo.save();
}